// @ts-ignore
import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';

export interface IndexModelState {
    id: string;//知识ID
    title:string;//知识标题
    baseInfo:String;//知识摘要
    customFields: AircasKB.Knowledge.CustomFieldVo[];//其他描述
    type:string;//知识类型
    setTargetKeys:any[];//知识分类
    labels:string[];//关键词

}

export interface IndexModelType {
    namespace: 'KnowledgeObj';
    state: IndexModelState;
    reducers: {
        save: Reducer<IndexModelState>;
    };
    subscriptions: { setup: Subscription };
}

const IndexModel: IndexModelType = {
    namespace: 'KnowledgeObj',
    state: {
        id: 'dddd',//知识ID
        title:'dddddd1',//知识标题
        baseInfo:'',//知识摘要
        customFields: [],//其他描述
        type:'',//知识类型
        setTargetKeys:[],//知识分类
        labels:[],//关键词
    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
    subscriptions: {
        setup({ dispatch, history }) {
            return history.listen(({ pathname }) => {
                if (pathname === '/') {
                    dispatch({
                        type: 'query',
                    });
                }
            });
        },
    },
};

export default IndexModel;